<template lang="en">
    <div class="demo">
        <h1>{{msg}}</h1>
        <h2>学生姓名：{{name}}</h2>
        <h2>学生性别：{{sex}}</h2>
        <h2>学生年龄：{{age}}</h2>
        <button @click="sendStudentName">把学生名传给School组件</button>
    </div>
</template>
<script>
import pubsub from 'pubsub-js'
export default {    
    name: 'School',
    data() {
        return {
            msg: '我是一个尚硅谷的学生'
            // name: '尚硅谷',
            // address: '北京昌平'
        }
    },
    props: ['name','age','sex'],
/*     // 简单传参
    // 接收的同时对数据进行类型限制
    props: {
        name: String,
        age: Number,
        sex: String
    },
    props: {
        name: {
            type:String,
            required:true
        },
        age: {
            type: Number,
            default: 23
        },
        sex: {
            type:String,
            required: true
        }
    }, */
    methods: {
        showName() {
            alert(this.name)
        },
        sendStudentName() {
            // this.$bus.$emit('hello',this.name)

            // 发布消息
            pubsub.publish('hello',666)
        },
        unbind() {
            this.$off('atguigu')
        },
        death() {
            this.$destroy()
        }
    }
}
</script>
<style>
    .demo {
        background-color: orangered;
    }
</style>